import java.util.*;

public class Anagram{
	public static void main(String[] args){
		
		Scanner in = new Scanner(System.in);
		
		//Ask to enter source for anagram
		System.out.println("Enter word or phrase: ");
		String firstWordInput = in.nextLine().toLowerCase().replaceAll("\\s","");

		char[] firstWord = firstWordInput.toCharArray();
		
		//Ask to enter anagram of source entered
		System.out.println("Enter anagram: ");
		String anagramInput = in.nextLine().toLowerCase().replaceAll("\\s","");

		char[] anagram = anagramInput.toCharArray();
			
			//Output to console depending on results of two methods
			if(isEqualLength(firstWordInput, anagramInput)){
				if(isAnagram(firstWord, anagram)){
					System.out.println("It's an anagram!");
				}
				else{
					System.out.println("Not anagram!");
				}				
		}
		else{
			System.out.println("Please, enter equal number of letters in each word or phrase");
			}		
	}
	//Method to check whether entered words are anagram by comparing two arrays of symbols
	public static boolean isAnagram(char[] arr1, char[] arr2){
		Arrays.sort(arr1);
		Arrays.sort(arr2);
			if(Arrays.equals(arr1, arr2)){
				return true;
			}
			else{
				return false;
			}			
	}
	//Method to check whether entered words or phrases have same number of letters
	public static boolean isEqualLength(String s1, String s2){
		if(s1.length() != s2.length()){
			return false;
		}
		return true;
	}
}